<template>
	<view>
		<map class="map" :latitude="latitude" :longitude="longitude" :markers="markers"></map>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				latitude: '',
				longitude: '',
				markers: '',
				type: 1,
			};
		},
		onLoad(option) {
			this.type = option.type
			uni.getLocation({
				type: 'wgs84',
				geocode: true, //设置该参数为true可直接获取经纬度及城市信息
				success: (res) => {
					this.latitude = res.latitude;
					this.longitude = res.longitude;
					this.markers = [{
						id: 1,
						latitude: res.latitude,
						longitude: res.longitude
					}]
				},
				fail: () => {
					uni.showToast({
						title: '获取地址失败，将导致部分功能不可用',
						icon: 'none'
					});
				}
			});
			uni.chooseLocation({
				success: res => {
					uni.$emit('chooseLocation',  {
						type : this.type,
						info : res
					});
					uni.navigateBack({
						delta:1
					})
				}
			});
		},
	}
</script>

<style lang="scss" scoped>
	.map {
		width: 100%;
		height: 100vh;
	}
</style>
